package com.weihuachao.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.weihuachao.repair.AddWorkActivity;
import com.weihuachao.repair.LoginActivity;
import com.weihuachao.repair.R;

/**
 * Created by Virgo on 2016/7/30.
 */
public class Profile_fragment extends Fragment implements View.OnClickListener {
    private View mLayout;
    private TextView weidenglu;
    private ImageView touxiang;
    private View addo;

    public Profile_fragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (mLayout == null) {
            mLayout = inflater.inflate(R.layout.fragment_profile, container, false);
            mLayout.findViewById(R.id.login_profile).setOnClickListener(this);
        }
        String string = com.weihuachao.app.application.getAccount();
        weidenglu = (TextView) mLayout.findViewById(R.id.dengluxinxi);
        if (string != null) {
            weidenglu.setText(string);
            touxiang = (ImageView) mLayout.findViewById(R.id.touxiang);
            touxiang.setImageDrawable(getResources().getDrawable(R.drawable.logined));
        }
        addo = mLayout.findViewById(R.id.addwork);
        addo.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (!weidenglu.getText().toString().equals("未登录")) {
                    startActivity(new Intent(Profile_fragment.this.getActivity(), AddWorkActivity.class));
                } else {
                    Toast.makeText(getActivity(), "请先登录！", Toast.LENGTH_SHORT).show();
                }
                return false;
            }
        });

        return mLayout;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.login_profile:
                if (weidenglu.getText().toString().equals("未登录")) {
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }
                break;
            default:
                break;
        }
    }
}
